package geeksforgeeks.trees;

import geeksforgeeks.trees.DepthTree.Node;

public class Root2LeafPath {
	public static void main(String[] args) {
		Node root = new Node(1);

		root.left = new Node(2);

		root.left.left = new Node(4);
		root.left.right = new Node(5);
		root.right = new Node(3);

		int[] path = new int[100];
		printRoot2LeafPath(root, path, 0);

	}

	public static void printRoot2LeafPath(Node root, int[] path, int level) {
		if (root == null)
			return;
		path[level++] = root.data;

		if (root.left == null && root.right == null) {
			for(int i = 0; i < level; i++) {
				System.out.printf("%d ", path[i]);
			}
			System.out.println();
			return;
		}
		printRoot2LeafPath(root.left, path, level);
		printRoot2LeafPath(root.right, path, level);
	}

}
